#include "TestEnvironment.h"
#include "BinaryChromosomeFactory.h"
#include "Chromosome.h"

TestEnvironment::TestEnvironment(int _populationSize,
                                 int chromosomeLength) :
                    AbstractEnvironment(_populationSize)
{
    setBestFitness(chromosomeLength);

    chromosomeFactory = new BinaryChromosomeFactory(chromosomeLength);
    //createPopulation();
}

void TestEnvironment::fitnessFunction(Chromosome& chrom)
{
    //qDebug() << "TestEnvironment::fitnessFunction";
    QString chromosomeString = chrom.toString();
    double fitness = 0.0;

    for(int i=0;i<chromosomeString.size();++i)
    {
        if( (i%2==0 && chromosomeString.at(i) == '1') || (i%2==1 && chromosomeString.at(i) == '0') )
            fitness += 1.0;
    }
    chrom.setFitness(fitness);
}
